// pages/goodsDetail/goodsDetail.js
Page({
    data: {
        obj: {},
        name: '',
        goods_id: '',
        textColorData: '#000000',
        backgroundData: 'transparent',
    },

    onLoad(options) {
        if (options) {
            const id = options.id;
            const name = options.name;
            this.setData({
                name,
                goods_id: id,
            });
            this.getDetail(id);
        }
    },

    getDetail(id) {
        this.request({
            url: 'user/index/goods/detail',
            data: {
                id,
            },
        }).then(res => {
            // console.log(res);
            this.setData({
                obj: res.data,
            });
        });
    },
    // 开启页面分享
    onShareAppMessage(e) {
        console.log(e);
    },
    // 加购
    addCart(e) {
        // console.log(this.data.goods_id);
        this.request({
            url: 'user/goodsCar/create',
            method: 'POST',
            data: {
                goods_id: this.data.goods_id,
                num: 1,
            },
            loadingTip: '加载中',
        }).then(res => {
            console.log(res);
            wx.showToast({
                title: res.msg,
            });
        });
    },

    navigatorSell(e) {
        // console.log();
        const fromTp = e.currentTarget.dataset.fromtype;
        wx.navigateTo({
            url: '/pages/settlementPage/settlementPage?id=' + this.data.goods_id + '&ftp=' + fromTp,
        });
    },

    navigatorCart() {
        wx.switchTab({
            url: '/pages/cart/cart',
        });
    },

    onPageScroll(e) {
        // console.log(e.scrollTop);
        if (e.scrollTop > 1) {
            this.setData({
                textColorData: '#000000',
                backgroundData: '#ffffff',
            });
        } else {
            this.setData({
                textColorData: '#000000',
                backgroundData: 'transparent',
            });
        }
    },
});
